home *** CD-ROM | disk | FTP | other *** search
/ AP Professional Graphics CD-ROM Library / AP Professional Graphics CD-ROM Library.iso / pc / unix / appendix / gemsi / polyscan / poly.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-26  |  2.1 KB  |  59 lines

  1. /* poly.h: definitions for polygon package */
  2.  
  3. #ifndef POLY_HDR
  4. #define POLY_HDR
  5.  
  6. #define POLY_NMAX 10        /* max #sides to a polygon; change if needed */
  7. /* note that poly_clip, given an n-gon as input, might output an (n+6)gon */
  8. /* POLY_NMAX=10 is thus appropriate if input polygons are triangles or quads */
  9.  
  10. typedef struct {        /* A POLYGON VERTEX */
  11.     double sx, sy, sz, sw;    /* screen space position (sometimes homo.) */
  12.     double x, y, z;        /* world space position */
  13.     double u, v, q;        /* texture position (sometimes homogeneous) */
  14.     double r, g, b;        /* (red,green,blue) color */
  15.     double nx, ny, nz;        /* world space normal vector */
  16. } Poly_vert;
  17. /* update poly.c if you change this structure */
  18. /* note: don't put > 32 doubles in Poly_vert struct, or mask will overflow */
  19.  
  20. typedef struct {        /* A POLYGON */
  21.     int n;            /* number of sides */
  22.     unsigned long mask;        /* interpolation mask for vertex elems */
  23.     Poly_vert vert[POLY_NMAX];    /* vertices */
  24. } Poly;
  25. /*
  26.  * mask is an interpolation mask whose kth bit indicates whether the kth
  27.  * double in a Poly_vert is relevant.
  28.  * For example, if the valid attributes are sx, sy, and sz, then set
  29.  *    mask = POLY_MASK(sx) | POLY_MASK(sy) | POLY_MASK(sz);
  30.  */
  31.  
  32. typedef struct {        /* A BOX (TYPICALLY IN SCREEN SPACE) */
  33.     double x0, x1;        /* left and right */
  34.     double y0, y1;        /* top and bottom */
  35.     double z0, z1;        /* near and far */
  36. } Poly_box;
  37.  
  38. typedef struct {        /* WINDOW: A DISCRETE 2-D RECTANGLE */
  39.     int x0, y0;            /* xmin and ymin */
  40.     int x1, y1;            /* xmax and ymax (inclusive) */
  41. } Window;
  42.  
  43. #define POLY_MASK(elem) (1 << (&poly_dummy->elem - (double *)poly_dummy))
  44.  
  45. #define POLY_CLIP_OUT 0        /* polygon entirely outside box */
  46. #define POLY_CLIP_PARTIAL 1    /* polygon partially inside */
  47. #define POLY_CLIP_IN 2        /* polygon entirely inside box */
  48.  
  49. extern Poly_vert *poly_dummy;    /* used superficially by POLY_MASK macro */
  50.  
  51. void    poly_print(/* str, p */);
  52. void    poly_vert_label(/* str, mask */);
  53. void    poly_vert_print(/* str, v, mask */);
  54. int    poly_clip_to_box(/* p1, box */);
  55. void    poly_clip_to_halfspace(/* p, q, index, sign, k, name */);
  56. void    poly_scan(/* p, win, pixelproc */);
  57.  
  58. #endif
  59.